package com.norway.sms;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class MainActivity extends BaseFragmentActivity
{

	private EditText edit_phone;
	private Spinner spinner_price;
	private Button btn_recharge;
	private String currentPrice;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		setAdapter();
	}
	
	@Override
	public void initView()
	{
		edit_phone=(EditText) findViewById(R.id.edit_phone);
		spinner_price=(Spinner) findViewById(R.id.spinner_price);
		btn_recharge=(Button) findViewById(R.id.btn_recharge);
		
		btn_recharge.setOnClickListener(this);
	}
	
	private void setAdapter()
	{
		final String price[]={"10Ԫ","30Ԫ","50Ԫ","100Ԫ"};
		ArrayAdapter<String> stringArray=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,price);
		spinner_price.setAdapter(stringArray);
		spinner_price.setOnItemSelectedListener(new OnItemSelectedListener()
		{

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
			{
				currentPrice=price[arg2];
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0)
			{
				
			}
			
		});
	}
	
	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.btn_recharge:
			
			String phone=edit_phone.getText().toString();
			Intent intent=new Intent(this,RechargeFragmentActivity.class);
			intent.putExtra("phone", phone);
			intent.putExtra("price", currentPrice);
			startActivity(intent);
			break;
		}
	}

}
